<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------

namespace Admin\Controller;

/**
 * 行为控制器
 * @author huajie <banhuajie@163.com>
 */
class NoticeController extends AdminController {


    /**
     * 学信认证
     */
    public function index(){
        $map =array();

        $list   =   $this->lists('Notice', $map);
        $this->assign('_list', $list);
        $this->meta_title = '通知列表';
        $this->display();
    }
    /**
     * @author huajie <banhuajie@163.com>
     */
    public function add(){
        if(IS_POST){
            $uid        = I('post.uid');
            $weixin     = I('post.weixin');
            $is_mobile  = I('post.is_mobile');
            $mobile     = I('post.mobile');
            $content    = I('post.content');

            $is_weixin  = 0;
            if(!empty($weixin)){
                $is_weixin = 1;
            }
            if(empty($mobile)){
                $this->error('手机号码不能为空');
            }elseif(isMobile($mobile)==false){
                $this->error('手机号码格式不正确');
            }elseif(empty($is_mobile)){
                $this->error('请选择通知类型');
            }
            $data = [
                'uid'        => $uid,
                'is_weixin'  => $is_weixin,
                'weixin'     => $weixin,
                'mobile'     => $mobile,
                'content'    => $content,
                'is_mobile'  => $is_mobile,
                'create_time'   => NOW_TIME,
                'update_time'   => 0,
                'status'        => 0,
            ];
            $model = M('Notice');
            $model->create($data);
            if($model->add()){
                $this->success('添加成功！',U('index'));
            }else{
                $this->error('添加失败');
            }
        }else{
            $this->meta_title = '添加通知';
            $this->display();
        }
    }
}
